
from asyncio import current_task
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.asyncio import AsyncSession, create_async_engine, async_scoped_session

engine = create_async_engine("mysql+aiomysql://root:new_password@127.0.0.1:3306/slag_test_platform")
# engine = create_async_engine("mysql+aiomysql://remote:new_password@10.10.10.39:3306/slag_test_platform")
# engine = create_async_engine("mysql+aiomysql://root:new_password@mysql:3306/slag_test_platform")

sessionLocal = sessionmaker(
    class_=AsyncSession,
    autocommit=False,
    autoflush=False,
    bind=engine
)

async def get_db_session() -> AsyncSession:
    async with sessionLocal() as session:
        yield session

async def get_async_session() -> async_scoped_session:
    return async_scoped_session(sessionLocal, scopefunc=current_task)


















